<?php
namespace app\index\controller;
use think\Controller;
use think\Request;

class Add extends Controller
{
    private $user;
   public function index(){

       //var_dump($this->user->id);exit;
        return $this->fetch();
   }

   public function add(){
       if(!session('blog_user','','blog')){
           $this->error('请您先登录',url('index/user/login'));
       }
       //获取到登录用户的值

       $this->user = session('blog_user','','blog');
       if(request()->isPost()) {

           $data = input('post.');

           $datas=[
               'title'=>$data['title'],
               'user_id' =>$this->user['id'],
               'content'=>$data["content"],
               'logimg'=>$data['logimg'],
           ];

           $validate = validate('Releases');
           if(!$validate->scene('add')->check($datas)) {
               $this ->error($validate ->getError());
           }
           $id = model('Releases')->add($datas);
           if ($id) {
               $this->success('添加成功');
           } else {
               $this->error('添加失败');
           }
       }else{
           return $this->fetch();
       }

   }
}
